<?php

defined('SYSPATH') or die('Access error!');

class Breadcrumbs
{

    private static $breadcrumbs = array();

    public static function clear()
    {
        self::$breadcrumbs = array();
    }

    public static function get()
    {
        return self::$breadcrumbs;
    }

    public static function add($title, $url = '')
    {
        if (!empty($title))
        {
            $crumb = Breadcrumb::factory()->set_title($title)->set_url($url);
            array_push(self::$breadcrumbs, $crumb);
        }
    }

    public static function render()
    {
        $str = "<div>" . __('current position') . "<a href='" . URL::site() . "'>" . __('home') . "</a>";
        if (count(self::$breadcrumbs) > 0)
        {
            foreach (self::$breadcrumbs as $key => $value)
            {
                $str .= "&nbsp;&raquo;&nbsp;<a href='" . $value->get_url() . "'>" . $value->get_title() . "</a>";
            }
        }
        $str .="</div>";

        return $str;
    }

}